using System;
using System.Collections.Generic;
using UnityEngine;
using QFramework;

// 1.请在菜单 编辑器扩展/Namespace Settings 里设置命名空间
// 2.命名空间更改后，生成代码之后，需要把逻辑代码文件（非 Designer）的命名空间手动更改
namespace QFramework.Example
{
	public partial class InventoryExample1 : ViewController
	{
		private void Awake()
		{
			ItemKit.LoadItemDatabase("ExampleItemDatabase");
			
			ItemKit.CreateSlotGroup("背包")
				.CreateSlot(ItemKit.ItemByKey[Items.item_iron_sword], 1)
				.CreateSlot(ItemKit.ItemByKey[Items.item_apple], 8);
		}

		private void OnGUI()
		{
			IMGUIHelper.SetDesignResolution(960, 540);

			// 绘制背包
			foreach (var slot in ItemKit.GetSlotGroupByKey("背包").Slots)
			{
				GUILayout.BeginHorizontal("box");
				if (slot.Count == 0)
				{
					GUILayout.Label($"格子：空");
				}
				else
				{
					GUILayout.Label($"格子：{slot.Item.GetName} x {slot.Count}");
				}
				GUILayout.EndHorizontal();
			}

			// 增加、删除物品
			foreach (var key in ItemKit.ItemByKey.Keys)
			{
				var slot = ItemKit.ItemByKey[key];
				GUILayout.BeginHorizontal();
				GUILayout.Label($"{slot.GetName}");
				if (GUILayout.Button("+"))
				{
					var result = ItemKit.GetSlotGroupByKey("背包").AddItem(key);
					if (!result.Succeed)
					{
						Debug.Log($"物品栏已满！");
					}
				}
				if (GUILayout.Button("-"))
				{
					ItemKit.GetSlotGroupByKey("背包").SubItem(key);
				}
				GUILayout.EndHorizontal();
			}
		}


	}
}
